<template>
	<view class="main" :style="{paddingBottom:(getSafeBottom )+'px'}">
		<navbar title="技能培训"></navbar>
		
		<view class="content" :style="{paddingTop:(getStateHeight + getNavbar  ) + 'px'}">
			<view class="item-box">
				<view class="item" v-for="item in dataList" :key="item.id"  @click="toDetail(item)">
					<view class="item-icon">
						<image :src="baseImage + item.picdir" mode="" v-if="item.picdir"></image>
						<image :src="imgUrl + 'gonIcon1.png'" mode="" v-else></image>
					</view>
					<view class="item-label">
						{{item.title}}
					</view>
				</view>
			</view>
		</view>
		
		<view class="main-bj">
			
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapGetters
	} from 'vuex';
	import Navbar from '@/components/Navbar.vue'
	import {getServeList} from "@/core/web-api/qiuzhiduan.js"
	export default {
		data(){
			return {
				dataList:[],
				page:{
					current:1,
					limit:30,
				}
			}
		},
		methods:{
			/**
			 * 跳转到小程序或者网页
			 * 跳转到网页/pages-companies/webview/webview?url=网址
			 * 跳转到小程序：
			 * 方式1：
			 * 填写appid和(path为空则跳转到首页)
			 * 方式2：
			 * 填写shortLink
			 * 对应网址为：https://developers.weixin.qq.com/miniprogram/dev/api/navigate/wx.navigateToMiniProgram.html
			 * wx.navigateToMiniProgram({
				  appId: '目标小程序的appId',
				  path: '目标小程序的页面路径',
				  extraData: {
					key1: 'value1',
					key2: 'value2'
				  },
				  envVersion: 'release', // 可选，指定环境版本
				  success(res) {
					// 成功回调
				  },
				  fail(err) {
					// 失败回调
				  }
				});
			 * @param {Object} item
			 */
			toDetail(item){
				if(item && item.title.indexOf("培训机构")!= -1){
					uni.navigateTo({
						url:"/pages/web/service/qiuzhiduan/peixunjigou",
					})
				}else{
					wx.navigateToMiniProgram({
						appId: item.url,
						path: item.path,
						extraData: {},
						envVersion: 'release', // 可选，指定环境版本
						success(res) {
							// 成功回调
						},
						fail(err) {
							// 失败回调
						}
					});
				}
			},
			/**
			 * 加载数据
			 */
			getList() {
				getServeList({
					...this.page,
					cataName:"技能培训"
				}).then(res => {
					if (res.code == 20000) {
						const {
							total,
							list
						} = res.data;
						if (this.page.current == 1) {
							this.dataList = list;
						} else {
							this.dataList.push(...list);
						}
						this.total = total;
					}
				})
			},
			
			/**
			 * 分页加载
			 */
			pageData() {
				if (this.total == this.dataList.length) return;
				this.page.current++;
				this.getList()
			},
		},
		components:{
			Navbar
		},
		computed: {
			...mapGetters(['getNavbar', 'getStateHeight', 'getSafeBottom']),
			...mapState(['baseImage','imgUrl'])
		},
		created() {
			this.getList()
		}
	}
</script>

<style scoped lang="less">
	.main {
		width: 100%;
		padding: 0 30upx;
		box-sizing: border-box;
	
		&-bj {
			width: 100%;
			height: 50vh;
			position: fixed;
			left: 0;
			top: 0;
			z-index: -1;
			background: linear-gradient(to bottom, #bdccfb, #f5f5f5);
		}
	}
	.content{
		margin-top: 30upx;
		display: flex;
		flex-flow: wrap;
		justify-content: center;
	}
	.item{
		width: 216upx;
		height: 216upx;
		background-color: #fff;
		border-radius: 20upx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin-left: 20upx;
		margin-bottom: 20upx;
		box-shadow: 12upx 0 28upx rgba(202,206,216,.35);
		&-box{
			width: 710upx;
			margin-left: -20upx;
			display: flex;
			flex-flow: wrap;
		}
		&-icon{
			width: 45upx;
			height: 45upx;
			image{
				width: 45upx;
				height: 45upx;
			}
		}
		&-label{
			width: 120upx;
			margin-top: 25upx;
			font-size: 26upx;
			color: #4d4d4d;
			text-align: center;
		}
	}
</style>